package com.acme.bankapp.domain.bank;

public class CheckingAccount extends AbstractAccount {
	private final String OVERDRAFT_MUST_BE_POSITIVE = "Overdraft must be positive";

	private double overdraft;

	public CheckingAccount(final double amount, final double overdraft) throws NegativeArgumentValueException {
		super(amount);
		if (overdraft < 0) {
			throw new NegativeArgumentValueException(OVERDRAFT_MUST_BE_POSITIVE);
		}
		this.overdraft = overdraft;
	}

	/**
	 * if balance is not enough for withdraw, use overdraft's resources
	 * @throws OverDraftLimitExceededException 
	 * */
	@Override
	public void withdraw(final double amount) throws OverDraftLimitExceededException {

		if ( amount > maximumAmountTowothdraw() )
		{
			throw new OverDraftLimitExceededException(maximumAmountTowothdraw());
		}

		setBalance(balance - amount);

	}

	@Override
	public double maximumAmountTowothdraw() {
		return getBalance() + getOverdraft();
	}

	public double getOverdraft() {
		return overdraft;
	}

}
